import concurrent.futures

# 线程数据共享
# 3个线程，每个线程都将字符列表中的每个字符与 1 异或
def func(tname):
     global word
     for i, char in enumerate(word):
          word[i] = chr(ord(char) ^ 1)
          print(f"{tname}: {word}\n", end="")
     return word
     # ['h', 'e', 'l', 'l', 'o']

if __name__ == "__main__":
     word = list("idmmn!vnsme")
     # 使用 with 语句来确保线程被迅速清理
     with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
        # submit 提交一个任务到线程池
        # map 提交多个任务到线程池 并行
        # shutdown 关闭线程池，等待所有任务完成
          future1 = executor.submit(func, "线程1")
          future2 = executor.submit(func, "线程2")
          future3 = executor.submit(func, "线程3")
          word = future1.result()
          word = future2.result()
          word = future3.result()
print("".join(word))
# 字符串拼接